<?php

namespace Admin\Controller;
/**
 * 工作计划
 * @author Dinghua
 *
 */
class TaskController extends AdminController{
	
	/**
	 * 工作计划列表
	 */
	public function index() {
		$map = array();
		$map['uid'] = UID;
		$list = $this->lists('Task', $map, 'id DESC');

		$this->assign('_list', $list);
		
		$this->meta_title = '工作计划列表';
		
		// 记录当前列表页的cookie
		Cookie('__forward__',$_SERVER['REQUEST_URI']);
		$this->display();
	}
	
	
	/**
	 * 添加工作计划
	 */
	 public function add() {
		
		$this->meta_title = '添加工作计划';
		$this->display();
		
	 }
	 
	 /**
	  * 编辑工作计划
	  */
	public function edit($id = NULL) {
		if (empty($id)) $this->error('参数错误！');
		$info = D('Task')->info($id);
		$this->assign('info', $info);
		$this->meta_title = '编辑工作计划';
		$this->display('add');
	}
	
	/**
	 * 查看
	 */
	public function view($id = NULL) {
		
		if (empty($id)) return $this->error('参数错误');
		
		$info = D('Task')->info($id);
		$this->assign('info', $info);
		$data['is_view'] = 0;
		$map['id'] = $id;
		M('Task')->where($map)->save($data);
		$this->meta_title = '查看工作计划';
		$this->display();
	}
	
	/**
	 * 删除
	 */
	public function del($id = NULL) {
		if (empty($id)) $this->error('参数错误');
		$Task = M('Task');
		$res = $Task->delete($id);
		if(!$res){
			$this->error($Task->getError());
		}else{
			$this->success('删除成功', Cookie('__forward__'));
		}
	}
	
	
	 /**
	 * 更新或新增一条数据
	 */
	public function update(){
	
		$Task = D('Task');
		if ( isset($_POST['reminder_time']) ) {
			$_POST['reminder_time'] = strtotime(I('reminder_time'));
		}
		$_POST['uid'] = UID;
		$res = $Task->update();
		if(!$res){
			$this->error($Task->getError());
		}else{
			$this->success($res['id']?'更新成功':'新增成功', Cookie('__forward__'));
		}
	}
	
	
}